package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduProgressDTO;
import com.zenith.edu.po.vo.EduProgressVO;
import com.zenith.edu.service.EduProgressService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/progress")
@Tag(name = "学习进度管理", description = "学习进度管理接口")
public class EduProgressController {
    
    @Autowired
    private EduProgressService eduProgressService;
    
    @SecurePostMapping(value = "/createProgress", roles = "ROLE_ADMIN", permission = "progress:create")
    @Operation(summary = "创建学习进度")
    public Result<EduProgressVO> createProgress(@RequestBody EduProgressDTO dto) {
        EduProgressVO progressVO = eduProgressService.createProgress(dto);
        return Result.success(progressVO);
    }
    
    @SecurePostMapping(value = "/getProgressById/{id}", roles = "ROLE_ADMIN", permission = "progress:read")
    @Operation(summary = "根据ID获取学习进度详情")
    public Result<EduProgressVO> getProgressById(@PathVariable Long id) {
        EduProgressVO progressVO = eduProgressService.getProgressById(id);
        if (progressVO == null) {
            return Result.fail("学习进度不存在");
        }
        return Result.success(progressVO);
    }
    
    @SecurePostMapping(value = "/updateProgress", roles = "ROLE_ADMIN", permission = "progress:update")
    @Operation(summary = "更新学习进度信息")
    public Result<EduProgressVO> updateProgress(@RequestBody EduProgressDTO dto) {
        EduProgressVO progressVO = eduProgressService.updateProgress(dto);
        return Result.success(progressVO);
    }
    
    @SecurePostMapping(value = "/deleteProgress/{id}", roles = "ROLE_ADMIN", permission = "progress:delete")
    @Operation(summary = "删除指定学习进度")
    public Result<Void> deleteProgress(@PathVariable Long id) {
        boolean result = eduProgressService.deleteProgress(id);
        if (!result) {
            return Result.fail("学习进度删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping(value = "/getProgressList", roles = "ROLE_ADMIN", permission = "progress:read")
    @Operation(summary = "获取学习进度列表")
    public Result<List<EduProgressVO>> getProgressList() {
        List<EduProgressVO> progressList = eduProgressService.getProgressList();
        return Result.success(progressList);
    }
}